trigger CXGMoveMembersToClosed on CXG_Campaign_Accounts__c (after insert) {
  
  //Trigger Name:CXGMoveMembersToClosed
  //Date:28th July 2011
  //Author:Manish Tiwari/Accenture
  //Requirement/Project Name:CXG
  //Requirement/Project Description:Once Campaign Member is Moved to Closed all the incoming Campaign Members related to that CSS ID should move to Closed.
  
  Set<Id> cssid= New Set<Id>();//Set for storing sorted List of Customer CSS Ids
  
  //Record Type Helper Class for CXG Campaign Record Type
  ID CxGCampaignMemberRecordTypeId= RecordTypeHelper.GetRecordTypeIdByDevName('CXG_Campaign_Accounts__c', 'Campaign_Member');
  for(CXG_Campaign_Accounts__c cm:Trigger.New)
      if(cm.RecordTypeId==CxGCampaignMemberRecordTypeId)
      {
       cssid.add(cm.Customer__c);//Adding CSS Customer Id to Declared Set
      }
  if(cssid.size()>0)
  {    
     List<CXG_Campaign_Accounts__c> cmlist=[Select Id,RecordTypeId,Status__c,Disposition__c,Customer_ID__c,Customer__r.Line_Disconnected_Fax_Line__c from CXG_Campaign_Accounts__c where Customer__c=:cssid AND RecordTypeId=:CxGCampaignMemberRecordTypeId AND Status__c != 'Closed' AND Customer__r.Line_Disconnected_Fax_Line__c = true limit 1000];   
    
  //List for stroring updated Campaign Members
  
  for(CXG_Campaign_Accounts__c cm:cmlist)    
   {
    if(cm.RecordTypeId==CxGCampaignMemberRecordTypeId && cm.Customer__r.Line_Disconnected_Fax_Line__c==True)
    {
     cm.Status__c='Closed';
     cm.Disposition__c='Line Disconnected / Fax Line';
    }
   } 
 try{
 Update cmlist; //Updated the Status of the incoming Members as Closed and Disposition as 'Line Disconnected / Fax Line'   
 }Catch(DMLException exe)   
  {     //System.Debug(exe);  
    }
  }
}